use data_transform::DefaultDataTransformer;
use model_graph_types::{
    database::{ConnectorProtocol, DataSource, DatabaseType},
    extractor::{ExtractFromDatabaseOption, MetadataExtractor, MetadataPackage},
    transform::{DataTransformOptions, DataTransformUnit, DataTransformer},
};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    tracing_subscriber::fmt()
        .with_max_level(tracing::Level::DEBUG)
        .init();
    tracing::info!("RRAI 启动...");

    let transform = DefaultDataTransformer {};

    let source_data_source = DataSource {
        database_type: DatabaseType::SQLite,
        protocol: ConnectorProtocol::SQLite,
        url: String::from("sqlite:C:\\Users\\jinisu\\rrg01/rrg01.sqlite"),
        username: None,
        password: None,
        options: None,
    };

    let target_data_source = DataSource {
        database_type: DatabaseType::SQLite,
        protocol: ConnectorProtocol::SQLite,
        url: String::from("sqlite:C:\\Users\\jinisu\\rrg01/rrg02.sqlite"),
        username: None,
        password: None,
        options: None,
    };

    let units = vec![
        DataTransformUnit::structs(&vec![String::from("_g01_meta_classes")])?,
        DataTransformUnit::values(
            &String::from("_g01_meta_classes"),
            &String::from(" where domain_identifier = 'mysql' "),
        )?,
    ];

    tracing::debug!("{:?}", serde_json::to_string(&units)?);

    let mut options = DataTransformOptions::default();
    options.ignore_errs = true;

    let _ = transform
        .transform(&source_data_source, &target_data_source, units, options)
        .await;

    Ok(())
}
